package com.a.ims.controller;


import com.a.ims.entity.Adminlog;
import com.a.ims.entity.User;
import com.a.ims.service.AdminlogService;
import com.a.ims.util.R;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class AdminlogContreller {
    @Autowired
    private AdminlogService adminlogService;

    @RequestMapping("/log")
   public  R<List<Adminlog>> log( HttpSession session) {
        //检测权限
        User user = (User) session.getAttribute("user");
        //检测登录
        if(user == null) {
            System.out.println("用户未登录！");
            return R.error("请先登录！");
        }
        //检测权限
        if(user.getPermission() < 2) {
            System.out.println("用户权限不足！");
            return R.error("权限不足！");
        }
        List <Adminlog> adminlogs = adminlogService.getAdminlog();
        if (adminlogs == null){
            System.out.println("查询失败！");
            return R.error("查询失败！");
        }
        System.out.println("查询成功！");
        return R.ok(adminlogs);
    }





}
